package org.setamv.springcloud.feign.integrated;

import org.setamv.springcloud.entity.User;
import org.setamv.springcloud.feign.contract.CustomizedHttpRequest;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 下面的"service"为负载均衡客户端名称。如"service.ribbon.serverList"中，"service"就是客户端名称。
 */
@FeignClient("service")
public interface SpringCloudFeignClient {

    /**
     * 实现简单的GET接口
     * @param yourName
     * @return
     */
    @RequestMapping(value = "/greetings/from/{yourName}", method = RequestMethod.GET)
    public String greetings(@PathVariable("yourName") String yourName);

    /**
     * 实现json格式的POST请求
     */
    @RequestMapping(value = "/user/echo/by/json", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    public User echoUserByJson(@RequestBody User user);

    /**
     * 实现xml格式的POST请求
     */
    @RequestMapping(value = "/user/echo/by/xml", method = RequestMethod.POST,
            produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE)
    public User echoUserByXml(@RequestBody User user);

    /**
     * 自定义注解。要使得该注解生效，必须启用 {@linkplain org.setamv.springcloud.feign.contract.ExSpringMVCContract} 类作为feign的Contract
     */
    @CustomizedHttpRequest(url = "/greetings/from/stamv", method = "GET")
    public String grettingsByCustomizedContract();
}
